#include "stdafx.h"

const float EPSILON = 0.0000003f;
const float PI = 3.1415926f;
const float PI2 = PI * 2;
const float PIBY2 = PI / 2;


void string2wstring(const std::string& str, std::wstring& out)
{
	std::wstring tmp(str.length(), L' '); // Make room for characters
	std::copy(str.begin(),str.end(),tmp.begin());
	out = tmp;
}

void wstring2String(const std::wstring& ws, std::string& out)
{
	out.assign(ws.begin(), ws.end());
}

float rad2Deg(float rad)
{
	return rad * 180 / PI;
}

float deg2Rad(float deg)
{
	return deg * PI / 180;
}

mat4f getProjectionMatrixRH(float halfAngleInDegree, float ratio, float znear, float zfar)
{
	mat4f matProjection;

	float zRange = znear - zfar;
	float tanHalfFOV = tanf(deg2Rad(halfAngleInDegree));

	matProjection.m[0] = 1.0f / (tanHalfFOV * ratio); 
	matProjection.m[1] = 0.0f;
	matProjection.m[2] = 0.0f;
	matProjection.m[3] = 0.0f;

	matProjection.m[4] = 0.0f; 
	matProjection.m[5] = 1.0f / tanHalfFOV; 
	matProjection.m[6] = 0.0f; 
	matProjection.m[7] = 0.0f;

	matProjection.m[8] = 0.0f; 
	matProjection.m[9] = 0.0f; 
	matProjection.m[10] = zfar / zRange; 
	matProjection.m[11] = -1.0f;

	matProjection.m[12] = 0.0f; 
	matProjection.m[13] = 0.0f; 
	matProjection.m[14] = zfar * znear / zRange;
	matProjection.m[15] = 0.0f;

	return matProjection;
}
